package com.xl.sharedModel;

import lombok.extern.slf4j.Slf4j;
import static java.lang.Thread.sleep;

/**
 * JdkVersion: 1.8
 * Author: lei·xie
 * Created: 2024/8/7 0007 10:44
 * Description: 共享模型 synchronized 线程八锁
 */
@Slf4j(topic = "c.Test4")
public class Test04 {
    public static void main(String[] args) throws InterruptedException {
        Number number = new Number();
        /*new Thread(() -> { log.debug("begin"); number.a(); }).start();
        new Thread(() -> { log.debug("begin"); number.b(); }).start();
        new Thread(() -> { log.debug("begin"); number.c(); }).start();*/

        new Thread(() -> { log.debug("begin"); number.a(); }).start();
        new Thread(() -> { log.debug("begin"); number.b(); }).start();
    }
}

@Slf4j(topic = "c.Number")
class Number {
    public synchronized void a() {
        log.debug("1");
    }

    public synchronized void b() {
        log.debug("2");
    }

}

/*@Slf4j(topic = "c.Number")
class Number {
    public synchronized void a() {
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.debug("1");
    }

    public synchronized void b() {
        log.debug("2");
    }

}*/

/*@Slf4j(topic = "c.Number")
class Number {
    public synchronized void a() {
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.debug("1");
    }

    public synchronized void b() {
        log.debug("2");
    }

    public void c() {
        log.debug("3");
    }
}*/

/*@Slf4j(topic = "c.Number")
class Number {
    public synchronized void a() {
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.debug("1");
    }

    public synchronized void b() {
        log.debug("2");
    }

}*/

/*@Slf4j(topic = "c.Number")
class Number {
    public static synchronized void a() {
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.debug("1");
    }

    public synchronized void b() {
        log.debug("2");
    }

}*/

/*@Slf4j(topic = "c.Number")
class Number {
    public static synchronized void a() {
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.debug("1");
    }

    public static synchronized void b() {
        log.debug("2");
    }

}*/

/*@Slf4j(topic = "c.Number")
class Number {
    public static synchronized void a() {
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.debug("1");
    }

    public static synchronized void b() {
        log.debug("2");
    }

}*/
